package cn.wolfcode.crm.service.imp;

import cn.wolfcode.crm.domain.MessageHistory;
import cn.wolfcode.crm.mapper.MessageHistoryMapper;
import cn.wolfcode.crm.service.IMessageHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MessageHistoryServiceImpl implements IMessageHistoryService {
    @Autowired
    private MessageHistoryMapper messageHistoryMapper;

    @Override
    public List<MessageHistory> selectAll() {
        return messageHistoryMapper.selectAll();
    }

    @Override
    public void saveOrUpdate(MessageHistory entity) {
        if (entity.getId() != null) {
            messageHistoryMapper.updateByPrimaryKey(entity);
        }else {
            entity.setDate(new Date());
            messageHistoryMapper.insert(entity);
        }
    }

    @Override
    public void delete(Long id) {
        messageHistoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public MessageHistory get(Long id) {
        return messageHistoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MessageHistory> list() {
        return messageHistoryMapper.selectAll();
    }

}
